package com.zhs.elasticsearch.service.impl;

import com.zhs.elasticsearch.basic.AjaxResult;
import com.zhs.elasticsearch.match.esRepository.UserRepository;
import com.zhs.elasticsearch.es.UserTermSearchService;
import com.zhs.elasticsearch.service.UserMatchService;
import com.zhs.elasticsearch.thread.UserSaveTask;
import com.zhs.elasticsearch.util.ThreadPoolUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ThreadPoolExecutor;

/**
 *
 * @Author zhenghuisheng
 * @Date：2025/6/23 15:50
 */
@Service
public class UserMatchServiceImpl implements UserMatchService {

    @Resource
    private UserRepository userRepository;

    @Resource
    private UserTermSearchService userTermSearchService;

    //获取线程池
    ThreadPoolExecutor threadPool = ThreadPoolUtil.getThreadPool();

    /**
     * 线程池批量生成100000个用户
     * @return
     */
    @Override
    public AjaxResult matchSave() {
        for (int i = 0; i < 1000; i++) {
            //提交任务
            threadPool.submit(new UserSaveTask(userRepository));
        }
        return AjaxResult.success("数据生成完毕");
    }

    @Override
    public AjaxResult matchSearch() {
        return userTermSearchService.matchSearch();
    }

}
